import request from "@/utils/request";

const AUTH_BASE_URL = "/admin/auth";

const AuthAPI = {
    /** 登录 接口*/
    login(data: LoginData) {
        const formData = new FormData();
        formData.append("username", data.username);
        formData.append("password", data.password);
        return request<LoginData, any>({
            url: `${AUTH_BASE_URL}/login`,
            method: "post",
            data: formData,
            headers: {
                "Content-Type": "multipart/form-data",
            },
        });
    },
    /** 发送短信 接口*/
    sendSms(data: sendSms) {
        const formData = new FormData();
        formData.append("tel", data.tel);
        formData.append("uid", String(data.uid));
        return request<any, any>({
            url: `${AUTH_BASE_URL}/sendSms`,
            method: "post",
            data: formData,
            headers: {
                "Content-Type": "multipart/form-data",
            },
        });
    },
    /** 校验验证码接口*/
    checkSms(data: checkSms) {
        const formData = new FormData();
        formData.append("captcha", data.captcha);
        formData.append("uid", String(data.uid));
        return request<checkSms, any>({
            url: `${AUTH_BASE_URL}/checkSms`,
            method: "post",
            data: formData,
            headers: {
                "Content-Type": "multipart/form-data",
            },
        });
    },

    /** 注销 接口*/
    logout() {
        return request({
            url: `${AUTH_BASE_URL}/signout`,
            method: "post",
        });
    },
};

export default AuthAPI;

/** 登录请求参数 */
export interface LoginData {
    /** 用户名 */
    username: string;
    /** 密码 */
    password: string;
}

/** 发送短信请求参数 */
export interface sendSms {
    /** 用户名 */
    tel: string;
    /** 密码 */
    uid: Number;
}

/** 校验验证码请求参数 */
export interface checkSms {
    /** 验证码 */
    captcha: string;
    /** 用户id */
    uid: Number;
}
